home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapsearch1.py < prev    next >
Text File  |  2004-01-05  |  7KB  |  260 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Implementation of QuArK Map editor features for the "Search" menu
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/mapsearch1.py,v 1.9 2003/12/17 13:58:59 peter-b Exp $
  12.  
  13.  
  14. Info = {
  15.    "plug-in":       "Basic Search",
  16.    "desc":          "Basic items for the Search menu.",
  17.    "date":          "31 oct 98",
  18.    "author":        "Armin Rigo",
  19.    "author e-mail": "arigo@planetquake.com",
  20.    "quark":         "Version 5.1" }
  21.  
  22.  
  23. import quarkpy.qmenu
  24. import quarkpy.qmacro
  25. import quarkpy.mapsearch
  26. import quarkpy.mapentities
  27. from quarkpy.maputils import *
  28.  
  29.  
  30. #
  31. # Search broken polyhedron and faces.
  32. #
  33.  
  34. def Brok1Click(m):
  35.     editor = mapeditor()
  36.     if editor is None: return
  37.     list = editor.Root.findallsubitems("", ':p')+editor.Root.findallsubitems("", ':f')
  38.     list = filter(lambda p: p.broken, list)
  39.     quarkpy.mapsearch.SearchResult(editor, list)
  40.  
  41.  
  42.  
  43. class SearchDlg(quarkpy.qmacro.dialogbox):
  44.  
  45.     src_backup = {}
  46.  
  47.     def __init__(self, reserved):
  48.         editor = mapeditor()
  49.         self.sellist = editor.visualselection()
  50.  
  51.         src = quarkx.newobj(":")
  52.         if not self.sellist:
  53.             src ["scope"] = "W"
  54.             src ["scope$Items"] = "Whole map"
  55.             src ["scope$Values"] = "W"
  56.         else:
  57.             src ["scope"] = "W"  ## "S"
  58.             src ["scope$Items"] = "Selection\nWhole map"
  59.             src ["scope$Values"] = "S\nW"
  60.  
  61.         src["kind"] = "e,b"
  62.         slist = ["All entities"]
  63.         klist = ["e,b"]
  64.         for key, value in quarkpy.mapentities.Mapping.items():
  65.             klist.append(key[1:])
  66.             if value.__class__.__doc__:
  67.                 slist.append(value.__class__.__doc__)
  68.             else:
  69.                 slist.append("'%s' objects" % key)
  70.         slist.append("All objects")
  71.         klist.append(",".join(klist[1:]))
  72.         src["kind$Items"] = "\015".join(slist)
  73.         src["kind$Values"] = "\015".join(klist)
  74.  
  75.         for key, value in self.src_backup.items():
  76.             src[key]=value
  77.  
  78.  
  79.         quarkpy.qmacro.dialogbox.__init__(self, quarkx.clickform, src,
  80.           ok = qtoolbar.button(self.search, "search for the given classname", ico_editor, 1, " Search ", 1),
  81.           cancel = qtoolbar.button(self.close, "close this box", ico_editor, 0, " Cancel ", 1))
  82.         self.editor = editor
  83.  
  84.     def search(self, reserved):
  85.         quarkx.globalaccept()
  86.         self.__class__.src_backup = self.src.dictspec
  87.         quarkpy.mapsearch.SearchResult(self.editor, self.search1())
  88.         self.close()
  89.  
  90.     def search_list(self, classname=None):
  91.         classname = classname or ""
  92.         if self.src["scope"] == "S" and self.sellist:
  93.             sellist = self.sellist
  94.         else:
  95.             sellist = self.editor.Root.subitems
  96.         list = []
  97.         def fix(s):
  98.             s = s.strip()
  99.             if s[:1] != ':':
  100.                 return ':'+s
  101.             return s
  102.         tlist = map(fix, self.src["kind"].split(","))
  103.         for obj in sellist:
  104.             for t in tlist:
  105.                 list = list + obj.findallsubitems(classname, t)
  106.         return list
  107.  
  108.  
  109. #
  110. # Search by Classname.
  111. #
  112.  
  113. class SearchByName(SearchDlg):
  114.  
  115.     #
  116.     # dialog layout
  117.     #
  118.  
  119.     size = (300, 194)
  120.     dfsep = 0.4        # separation at 40% between labels and edit boxes
  121.  
  122.     dlgdef = """
  123.       {
  124.         Style = "15"
  125.         Caption = "Search by classname"
  126.         sep: = {Typ="S" Txt=" "}
  127.         classname: = {
  128.           Txt = " Search for :"
  129.           Typ = "E"
  130.           SelectMe = "1"
  131.         }
  132.         scope: = {
  133.           Typ = "CL"
  134.           Txt = " Search in :"
  135.           Items = "%s"
  136.           Values = "%s"
  137.         }
  138.         kind: = {
  139.           Typ = "C"
  140.           Txt = " Object type :"
  141.           Items = "%s"
  142.           Values = "%s"
  143.         }
  144.         sep: = {Typ="S" Txt=" "}
  145.         ok:py = { }
  146.         cancel:py = { }
  147.       }
  148.     """
  149.  
  150.     def search1(self):
  151.         return self.search_list(self.src["classname"])
  152.  
  153.  
  154. #
  155. # Search by Specific/Arg.
  156. #
  157.  
  158. class SearchBySpec(SearchDlg):
  159.  
  160.     #
  161.     # dialog layout
  162.     #
  163.  
  164.     size = (300, 214)
  165.     dfsep = 0.4        # separation at 40% between labels and edit boxes
  166.  
  167.     dlgdef = """
  168.       {
  169.         Style = "15"
  170.         Caption = "Search by Specific/Arg"
  171.         sep: = {Typ="S" Txt=" "}
  172.         spec: = {
  173.           Txt = " Search for Specific :"
  174.           Typ = "E"
  175.           SelectMe = "1"
  176.           Hint = "Specific to search for (optionnal)"
  177.         }
  178.         arg: = {
  179.           Txt = " Search for Arg :"
  180.           Typ = "E"
  181.           Hint = "Arg to search for (optionnal)"
  182.         }
  183.         scope: = {
  184.           Typ = "CL"
  185.           Txt = " Search in :"
  186.           Items = "%s"
  187.           Values = "%s"
  188.         }
  189.         kind: = {
  190.           Typ = "C"
  191.           Txt = " Object type :"
  192.           Items = "%s"
  193.           Values = "%s"
  194.         }
  195.         sep: = {Typ="S" Txt=" "}
  196.         ok:py = { }
  197.         cancel:py = { }
  198.       }
  199.     """
  200.  
  201.     def search1(self):
  202.         spec = self.src["spec"]
  203.         arg = self.src["arg"]
  204.         list = self.search_list()
  205.  
  206.         if not spec:
  207.             if not arg:
  208.                 testfn = lambda x: 1
  209.             else:
  210.                 def testfn(obj, arg0=arg):
  211.                     for spec, arg in obj.dictspec.items():
  212.                         if arg == arg0:
  213.                             return 1
  214.                     return 0
  215.         else:
  216.             if not arg:
  217.                 def testfn(obj, spec0=spec):
  218.                     return obj[spec0]
  219.             else:
  220.                 def testfn(obj, spec0=spec, arg0=arg):
  221.                     return obj[spec0]==arg0
  222.  
  223.         return filter(testfn, list)
  224.  
  225.  
  226.  
  227. #
  228. # Register these new menu items for the "Search" menu.
  229. #
  230.  
  231. quarkpy.mapsearch.items.append(quarkpy.qmenu.item("Object by &name", SearchByName, "|Object by name:\n\nThis function will search for an object (which are also called Entities) by its 'classname' (the type of game entity it represents, a particular monster, weapon, item...).", "intro.mapeditor.menu.html#searchmenu"))
  232. quarkpy.mapsearch.items.append(quarkpy.qmenu.item("Object by &Specific/Aug", SearchBySpec, "|Object by Specific/Aug:\n\nThis function will search for all objects (which are also called Entities) by a particular Specific (key) or Argument (value) setting.", "intro.mapeditor.menu.html#searchmenu"))
  233. quarkpy.mapsearch.items.append(quarkpy.qmenu.item("&Broken polys and faces", Brok1Click, "|Broken polys and faces:\n\nThis function will search your map for any invalid polyhedrons and faces which do not belong to a polyhedron.", "intro.mapeditor.menu.html#searchmenu"))
  234.  
  235.  
  236. # ----------- REVISION HISTORY ------------
  237. #
  238. #
  239. # $Log: mapsearch1.py,v $
  240. # Revision 1.9  2003/12/17 13:58:59  peter-b
  241. # - Rewrote defines for setting Python version
  242. # - Removed back-compatibility with Python 1.5
  243. # - Removed reliance on external string library from Python scripts
  244. #
  245. # Revision 1.8  2003/03/21 05:47:45  cdunde
  246. # Update infobase and add links
  247. #
  248. # Revision 1.7  2002/04/07 12:46:06  decker_dk
  249. # Pretty separator.
  250. #
  251. # Revision 1.6  2001/10/08 22:44:09  tiglari
  252. # revert to original and redo indent fix and separators
  253. #
  254. # Revision 1.2  2000/06/03 10:25:30  alexander
  255. # added cvs headers
  256. #
  257. #
  258. #
  259. #
  260.